package com.servlet.JeuDeLaBiere;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.servlet.JeuDeLaBiere.Model.Main;
import com.servlet.JeuDeLaBiere.Model.Partie;

public class ServletGamePage extends HttpServlet {
	
	private static final long serialVersionUID = 1L;

	public void doGet(	HttpServletRequest request, 
			HttpServletResponse response)
					throws IOException, ServletException{
		
		ServletContext context = this.getServletContext();	
		String nomPartie = request.getParameter("nomPartie");
		Partie maPartie = ((Main)context.getAttribute("Serveur")).getPartie(nomPartie);
		String nomJoueur = request.getParameter("nomJoueur");	
		request.setAttribute("nomPartie", nomPartie);
		request.setAttribute("nomJoueur", nomJoueur);
		request.setAttribute("maPartie", maPartie);
		if(maPartie.getTour()==(maPartie.getNbTours()-3)) {
			request.getRequestDispatcher("jsp/results.jsp").forward(request, response);
		}
		else {
			request.getRequestDispatcher("jsp/gamepage.jsp").forward(request, response);
		}
	}
	

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}
};
